/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');

module.exports = function (ctx, pluginOpts) {
  ctx.onBuildStart(() => {
    console.log('插件入参：', pluginOpts);
    console.log('编译开始');
  });

  ctx.modifyWebpackChain(({ chain, webpack, data }) => {
    console.log('这里可以修改webpack配置');
    // 示例：利用webpackChain向html中插入脚本
    if (process.env.TARO_ENV !== 'h5') return;

    const config = data.componentConfig;
    // 将 picker 加入默认配置
    // config.includes.add('picker');

    // 或者设置默认加载所有组件
    config.includeAll = true;
    // console.log('修改webpack配置', config);
  });

  ctx.onBuildComplete(() => {
    console.log('Taro 构建完成！');
  });

  ctx.modifyBuildAssets(({ assets }) => {
    console.log('修改编译后的结果');
  });

  ctx.onBuildFinish(() => {
    console.log('Webpack 编译结束！');
  });
};
